/**
 * problem_035.cpp
 * Copyright (C) 2011 - xrose
 */

#include <iostream>
#include <stdio.h>
#include <math.h>

#define MAXP 1000000
using namespace std;
int primes[MAXP] = {0};
int init()
{
    int flag = 1;
	primes[2]=1;
	for(int i=3; i<=MAXP; i++)
	{

		for(int j=2; j<= sqrt(i); j++)
		{
		    if(primes[j]==1)
		    {
                if((i%j ==0))
                {
                    flag = 0;
                    break;
                } else
                {
                    flag =1;
                }
		    }
		}
        primes[i]=flag;
	}
}
int isCirclePrime(const int abc)
{
    int cirabc = abc;
    int c;
    int nod = 0; //number of digits
    while(cirabc>0)
    {
        nod++;
        cirabc = (cirabc-(cirabc%10))/10;
    }
//    cout<<"nod= "<<nod<<endl;
    cirabc = abc;
    for(int i=0; i<nod; i++)
    {
        c = cirabc%10;
        cirabc = (cirabc-c)/10 + c*pow(10, nod-1);
        if(primes[cirabc])
        {
            continue;
        } else
        {
            return 0;
        }
    }
    return 1;
}
int main (int argc, char const* argv[])
{
    int amount = 0;
    init();
	for(int i=0; i<MAXP; i++)
	{
		if((primes[i] == 1)&&(isCirclePrime(i)))
		{
		    amount++;
			cout<<i<<endl;
		}
	}
	cout<<"--"<<amount<<endl;
	return 0;
}
